fix: defer code review editor construction for collapsed file diffs (APP-4518)#11250
Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
Draft
Conversation
Fixes a memory spike (~9GB heap, Sentry issue 7259255054) caused by CodeReviewView::build_view_state_for_file_diffs eagerly constructing editor state (GlobalBufferModel, CodeEditorView, layout computation) for every file diff including collapsed ones that are never rendered. Changes: - Check should_auto_expand_file BEFORE creating editor state. Collapsed files now store only content_at_head (a plain String) instead of a full editor view with styled buffer blocks. - Add ensure_editor_for_file() for lazy on-demand editor creation when the user expands a previously-collapsed file. - Wire lazy creation into ToggleFileExpanded and FileSelected handlers. - Keep content_at_head fresh in the single-file update path so lazy creation uses up-to-date content. For a PR with N collapsed files this avoids ~4.5GB of allocations from CodeEditorView constructors (2.52GB) and layout invalidation (2.00GB) that were shown in the heap profile. APP-4518 Co-Authored-By: Oz <oz-agent@warp.dev>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix a memory spike in code review diff rendering (Sentry issue #7259255054) where
CodeReviewView::build_view_state_for_file_diffseagerly constructs editor state (GlobalBufferModel, CodeEditorView, styled buffer blocks, full layout computation) for every file diff — including collapsed files that are never rendered.Root cause: Editor and global-buffer construction happened unconditionally for all non-binary files. Only afterward was the expansion state checked. For large PRs with many files, the majority are collapsed (binary, autogenerated, or large), yet each still materialized ~50-100MB of styled buffer data, pushing total in-use heap to ~9GB.
Fix: Defer editor construction for collapsed files. Only the lightweight
content_at_headstring is stored; the full editor is created lazily when the user expands the file viaensure_editor_for_file().Impact from heap profile:
CodeEditorViewconstructors: 2.52GB → 0 for collapsed filesBuffer::invalidate_layout_internal: 2.00GB → 0 for collapsed filesGlobalBufferModel::populate_buffer_with_read_content: 0.76GB → 0 for collapsed filesLinked Issue
APP-4518
Sentry #7259255054
The linked issue is labeled
ready-to-specorready-to-implement.Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes).
Testing
Verified the change compiles cleanly with
cargo clippy -p warp --all-targets -- -D warningsRan
cargo fmtwith no formatting issuesExisting unit tests in
code_review_view_tests.rspass (updated test to include newcontent_at_headfield)The change is behavioral: collapsed files now start without editors, and editors are created on-demand when expanded. All existing expansion/selection/comment code paths that reference
editor_statealready handleNonegracefully.I have manually tested my changes locally with
./script/runAgent Mode
Conversation: https://staging.warp.dev/conversation/8cd0fec7-59be-4a0c-88c9-d8f2a02cac88
Run: https://oz.staging.warp.dev/runs/019e3d9b-6ab9-7405-8e98-43f8c4aedb46
This PR was generated with Oz.